package com.wfs.myapp.repository;

import com.wfs.myapp.entity.domain.User;
import com.wfs.myapp.entity.vo.SearchVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @author Administrator
* @description 针对表【user(员工信息表)】的数据库操作Mapper
* @createDate 2024-05-13 15:40:28
* @Entity com.yixin.hospital.entity.domain.User
*/
public interface UserRepository extends JpaRepository<User, Long> {

    User findByOpenid(String openid);

    @Query(nativeQuery = true, value = " SELECT u.* " +
            " FROM bk_group_member gm LEFT JOIN user u ON gm.user_id = u.id " +
            " WHERE gm.group_id in (?1) " +
            " group by u.id " +
            " ORDER BY gm.created_time "
    )
    List<User> findByGroupIdIs(List<Long> groupIds);

    @Query(nativeQuery = true, value = " " +
            " SELECT 1 as type, u.id, u.nickname name, u.avatar image, u.status " +
            "FROM user u " +
            "WHERE u.nickname like CONCAT('%',:name,'%') "
            )
    List<SearchVo.SearchItem> findBySearchName(String name);
}




